package com.ye.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ye.annotion.ApiAnnotation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @author: scott
 * @date: 2022年04月20日 19:27
 */
@RestController
@RequestMapping("/hystrix")
public class HystrixController {

    @GetMapping("/calculate")
    @ApiAnnotation
    @SentinelResource("calculate")
    public String calculate(String a, String b, String type) {
        int result = 0;
        int num1 = Integer.parseInt(a);
        int num2 = Integer.parseInt(b);
        switch (type) {
            case "+":
                result = num1 + num2;
                break;
            case "-":
                result = num1 - num2;
                break;
            case "*":
                result = num1 * num2;
                break;
            case "/":
                result = num1 / num2;
                break;
        }
        return String.valueOf(result);
    }
}
